//
//  MeHearView.m
//  Ginix
//
//  Created by 冯志强 on 2025/2/17.
//

#import "MeHearView.h"

@interface MeHearView()
@property (nonatomic,strong) UIImageView * iconView;
@property (nonatomic,strong) UIImageView * headView;
@property (nonatomic,strong) UILabel     * nameLabel;
@property (nonatomic,strong) UIImageView * sexView;
@property (nonatomic,strong) UILabel     * ageLabel;
@property (nonatomic,strong) UILabel     * heightLabel;
@property (nonatomic,strong) UILabel     * wegihtLabel;
@property (nonatomic,strong) UIButton    * nextBtn;

@end

@implementation MeHearView

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        [self setSubViewLayout];
    }
    return self;
}

-(void)setSubViewLayout{
    
    [self addSubview:self.iconView];
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(28 * FMScaleX);
        make.size.mas_offset(CGSizeMake(80 * FMScaleX, 80* FMScaleX));
        make.top.mas_equalTo(20 * FMScaleX);
    }];
    
    [self addSubview:self.headView];
    [_headView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.iconView).insets(UIEdgeInsetsMake(8* FMScaleX, 8* FMScaleX, 8* FMScaleX, 8* FMScaleX));
    }];
    
    [self addSubview:self.nameLabel];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(20 * FMScaleX);
        make.top.equalTo(self.iconView.mas_top).offset(8 * FMScaleX);
    }];
    [self addSubview:self.sexView];
    [_sexView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(30 * FMScaleX, 22* FMScaleX));
        make.left.equalTo(self.nameLabel.mas_right).offset(13 * FMScaleX);
        make.centerY.equalTo(self.nameLabel);
    }];
    [self addSubview:self.nextBtn];
    [_nextBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(30 * FMScaleX, 30 * FMScaleX));
        make.right.mas_offset(-15 * FMScaleX);
        make.centerY.equalTo(self.iconView);
    }];
    [self addSubview:self.ageLabel];
    [_ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(20 * FMScaleX);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(16 * FMScaleX);
        make.height.mas_offset(22 * FMScaleX);
    }];
    [self addSubview:self.heightLabel];
    [_heightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.ageLabel);
        make.left.equalTo(self.ageLabel.mas_right).offset(8 * FMScaleX);
        make.height.mas_offset(22 * FMScaleX);
    }];
    [self addSubview:self.wegihtLabel];
    [_wegihtLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.ageLabel);
        make.left.equalTo(self.heightLabel.mas_right).offset(8 * FMScaleX);
        make.height.mas_offset(22 * FMScaleX);
    }];
    
}

-(void)setInfoModel:(UserInfoModel *)infoModel{
    
    self.nameLabel.text = infoModel.nickName;
    if (infoModel.height.length > 0 ) {
        self.heightLabel.text = [NSString stringWithFormat:@" %@CM ",infoModel.height];
        self.heightLabel.hidden = NO;
    }
    if (infoModel.weight.length > 0 ) {
        self.wegihtLabel.text = [NSString stringWithFormat:@" %@KG ",infoModel.weight];
        self.wegihtLabel.hidden = NO;
    }
    if (infoModel.avatar.length > 0) {
        [self.headView sd_setImageWithURL:[NSURL URLWithString:infoModel.avatar]];
    }
    if (infoModel.birthday.length > 0) {
        NSInteger age = [infoModel.birthday stringWithBirthy];
        self.ageLabel.text = [NSString stringWithFormat:@" %ld岁 ",age];
        self.ageLabel.hidden = NO;
    }
    
    self.sexView.image = infoModel.sex == 1 ? [UIImage imageNamed:@"Me_sex_boy"] : [UIImage imageNamed:@"Me_sex_gril"];
    self.sexView.hidden = NO;
}

-(void)nextBtnAction{
    
    id vc = [[NSClassFromString(@"MeSetInfoVC") alloc]init];
    [[UIViewController findNavigationController] pushViewController:vc animated:YES];
}

-(UIImageView *)headView{
    
    if (!_headView) {
        _headView = [[UIImageView alloc]init];
        [_headView setCornerRadius:32 * FMScaleX];
        _headView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _headView;
}

-(UIImageView *)iconView{
    
    if (!_iconView) {
        _iconView = [[UIImageView alloc]init];
        _iconView.image = [UIImage imageNamed:@"Me_icon_bg"];
    }
    return _iconView;
}
-(UILabel *)nameLabel{
    
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = Bold(18);
        _nameLabel.textColor = RDRGB(0x333333);
    }
    return _nameLabel;
}
-(UIImageView *)sexView{
    
    if (!_sexView) {
        _sexView = [[UIImageView alloc]init];
        _sexView.image = [UIImage imageNamed:@"Me_sex_gril"];
        _sexView.hidden = YES;
    }
    return _sexView ;
}
-(UILabel *)ageLabel{
    
    if (!_ageLabel) {
        _ageLabel = [[UILabel alloc]init];
        _ageLabel.textColor = RDRGB(0x9A7742);
        _ageLabel.backgroundColor = RGBA(172, 144, 91, 0.27);
        _ageLabel.font = Regular(12);
        [_ageLabel setCornerRadius:4 * FMScaleX];
        _ageLabel.hidden = YES;
    }
    return _ageLabel;
}
-(UILabel *)heightLabel{
    
    if (!_heightLabel) {
        _heightLabel = [[UILabel alloc]init];
        _heightLabel.textColor = RDRGB(0x9A7742);
        _heightLabel.backgroundColor = RGBA(172, 144, 91, 0.27);
        _heightLabel.font = Regular(12);
        [_heightLabel setCornerRadius:4 * FMScaleX];
        _heightLabel.hidden = YES;
    }
    return _heightLabel;
}
-(UILabel *)wegihtLabel{
    
    if (!_wegihtLabel) {
        _wegihtLabel = [[UILabel alloc]init];
        _wegihtLabel.textColor = RDRGB(0x9A7742);
        _wegihtLabel.backgroundColor = RGBA(172, 144, 91, 0.27);
        _wegihtLabel.font = Regular(12);
        [_wegihtLabel setCornerRadius:4 * FMScaleX];
        _wegihtLabel.hidden = YES;
    }
    return _wegihtLabel;
}
-(UIButton *)nextBtn{
    
    if (!_nextBtn) {
        _nextBtn = [[UIButton alloc]init];
        [_nextBtn setImage:[UIImage imageNamed:@"Me_head_arrow"] forState:UIControlStateNormal];
        [_nextBtn addTarget:self action:@selector(nextBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _nextBtn;
}

@end

